
rev1([],L,L).
rev1([X|L],L2,L3) :- rev1(L,[X|L2],L3).

palindrome(List) :- rev1(List,[],List).

invierteacu(L1,L2):-inversa(L1,[],L2).
inversa([],L,L).
inversa([X|L],Acum,Sal):-inversa(L,[X|Acum],Sal).


trio([],[]).
trio([[X,Y,Z]|Resto],[W|Sal]):-
        Q is Z/2,
        Q=:=0,
        W is X+Y,
        trio(Resto,Sal),!.
trio([[X,Y,Z]|Resto],[W|Sal]):-
        W is X*Y,
        trio(Resto,Sal),!.
        
quita_ult([X],X,[]).
quita_ult([X|R],U,[X|T]):-
        quita_ult(R,U,T).
palindromo(L):-
        palindromo(L,L).
palindromo([X|R],L):-
        quita_ult(L,U,T),
        X=:=U,
        palindromo(R,T).
palindromo([],[]).

f(e(d(e(b(A)),Z),Y),X)=f(e(d(c(b(x)),y),z),a)
f(e(d(c(b(A)),A),x),W)=f(e(d(c(Z),a),X,A)
p(X,f(X,Y),a,f,d,Z)=p(a,f(W,b),W,E,d,a)
p(g(f(Y,Z),q)1,2,A)=p(g(X,B),Y,Y+Y,Z)
p(g(Y,H),a,b,Z)=p(g(f(X,W),X),W,Z,V)
q(A,q(A,q(A)),q(A))=q(2,q(W,q(2)),f(2))


p(X,f(Z),g(4,h),Z)=p(2,f(g(2)),g(Y,h),g(X))	
q(f(X),X,g(X),X,2)=q(Z,1,h(Y),+(1,0),B)
r(g(X),h(7,14),r,r(X,Z))=r(Y,h(Z,B),X,r(v,7))
p(p(A,3),Z,q(h(3,b)),7)=p(B,B,q(A),A)
q(f(X),X,h(X),W,2)=q(Z,1,h(Y),+(1,0),B)
r(r(A,r(r(2),r(1)),Z),r(2))=r(r(r(Y),r(Z,A),r(X)),r(X))